//
//  MineTableViewCell.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/9.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "MineTableViewCell.h"
#define getBtnH 35/WIDTH_6_SCALE
@interface MineTableViewCell()
@property (nonatomic, strong)UIImageView * iconImg;
@property (nonatomic, strong)UILabel * projectTitleLab;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)UIButton * getBtn;
@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)NSString * rightID;
@end

@implementation MineTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        __weak typeof (self)weakSelf = self;
        [self.contentView addSubview:self.iconImg];
        [self.contentView addSubview:self.projectTitleLab];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.getBtn];
        [self.contentView addSubview:self.lineView];
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(15/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_top).mas_offset(18/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.lineView.mas_top).mas_offset(-16/WIDTH_6_SCALE);
            make.width.mas_offset(137/WIDTH_6_SCALE);
        }];
        [self.projectTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.iconImg.mas_right).mas_offset(21/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.iconImg.mas_top).mas_offset(7/WIDTH_6_SCALE);
            make.height.mas_offset(14/WIDTH_6_SCALE);
        }];
        [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.projectTitleLab);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-34/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.projectTitleLab.mas_bottom).mas_offset(10/WIDTH_6_SCALE);
            make.height.lessThanOrEqualTo(@(45/WIDTH_6_SCALE));
        }];
        [self.getBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.projectTitleLab.mas_left);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-20/WIDTH_6_SCALE);
            make.height.mas_offset(getBtnH);
            make.bottom.equalTo(weakSelf.lineView.mas_top).mas_offset(-16/WIDTH_6_SCALE);
        }];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(weakSelf.contentView);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
    }return self;
}
- (UILabel *)projectTitleLab{
    if (!_projectTitleLab) {
        _projectTitleLab = [[UILabel alloc] init];
        _projectTitleLab.font = DEF_FontSize_14;
        _projectTitleLab.textColor = [UIColor blackColor];
        _projectTitleLab.textAlignment = NSTextAlignmentLeft;
        _projectTitleLab.text = @"抗癌计划";
        _projectTitleLab.backgroundColor = [UIColor whiteColor];
    }return _projectTitleLab;
}
- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_13;
        _contentLab.textColor = getColor(@"ababab");
        _contentLab.textAlignment = NSTextAlignmentLeft;
        _contentLab.numberOfLines = 0;
        _contentLab.lineBreakMode = 0;
        _contentLab.text = @"胃癌、肝癌等各种癌症；出生后28-65周岁";
    }return _contentLab;
}
- (UIButton *)getBtn{
    if (!_getBtn) {
        _getBtn = [[UIButton alloc] init];
        _getBtn.titleLabel.font = DEF_FontSize_15;
        [_getBtn setBackgroundImage:[UIImage imageNamed:@"maself_bg"] forState:UIControlStateNormal];
        [_getBtn setTitle:@"领取权益" forState:UIControlStateNormal];
        [_getBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _getBtn.layer.cornerRadius = getBtnH/2;
        _getBtn.layer.masksToBounds = YES;
        [_getBtn addTarget:self action:@selector(getBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _getBtn;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = getColor(@"f7f7f7");
    }return _lineView;
}
- (UIImageView *)iconImg{
    if (!_iconImg) {
        _iconImg = [[UIImageView alloc] init];
//        _iconImg.backgroundColor = [UIColor redColor];
        _iconImg.image = [UIImage imageNamed:@"family_icon"];
    }return _iconImg;
}
- (void)getBtnClick{
    if (self.getRightBlock) {
        self.getRightBlock(self.rightID);
    }
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.iconImg.image = [UIImage imageNamed:model[@"img"]];
    self.projectTitleLab.text = model[@"title"];
    self.contentLab.text = model[@"content"];
//    self.rightID = model[@"rightID"];
}
@end
